#include "../lib/localmap.hpp"

using namespace pipc;

LocalMap::LocalMap()
{
    running_ = false;
}

void LocalMap::clear()
{
    boost::unique_lock< boost::shared_mutex > lock(serializer_);
    settings_.clear();
}

bool LocalMap::setValue(std::string key, Record value)
{
    boost::unique_lock<boost::shared_mutex > lock(serializer_);
    settings_.insert(std::make_pair(key,value));
    return true;
}

Record LocalMap::getValue(std::string key)
{
    Record ret;
    boost::shared_lock<boost::shared_mutex> lock(serializer_);
    if(settings_.find(key) == settings_.end())
    {
        gettimeofday(&(ret.effective), NULL);
        return ret;
    }
    return settings_.at(key);
}

bool LocalMap::start()
{
    running_ = true;
    return true;
}

bool LocalMap::stop()
{
    running_ = false;
    return true;
}

bool LocalMap::isSynced(std::string key)
{
    return true;
}

bool LocalMap::isRunning()
{
    return running_;
}

bool LocalMap::subscibe(std::string key, bool reader)
{
    return true;
}
